# coding:utf-8

import angr
from Angr.projectInfo import project_info


class Init:
    def __init__(self, project_name, args=None, main_opts={}, lib_opts={}):
        self.proj = angr.Project(project_name, main_opts=main_opts, lib_opts=lib_opts)
        project_info['arch'] = self.proj.arch
        project_info['entry'] = hex(self.proj.entry)
        project_info['filename'] = self.proj.filename
        project_info['bits'] = self.proj.arch.bits
        project_info['bytes'] = self.proj.arch.bytes
        project_info['shared_objects'] = self.proj.loader.shared_objects
        project_info['all_objects'] = self.proj.loader.all_objects
        project_info['main_objects'] = self.proj.loader.main_object
        project_info['min_addr'] = self.proj.loader.min_addr
        project_info['max_addr'] = self.proj.loader.max_addr
        project_info['execstack'] = self.proj.loader.main_object.extern_object
        project_info['pic'] = self.proj.loader.main_object.pic

    def blocks_search(self, entry):
        block = self.proj.factory(entry)
        return block.pp(), block.instructions, block.instructions_addrs

    def get_symbol(self):
        return self.proj.loader.main_object.imports

    def get_simstate(self):
        state = self.proj.factory.entry_state()
        return state

